// 导入模块
import request from "../utils/request";


// 新建一个类 
class BaseAPI {
    // 属性 
    public appname : string ;
    public name: string;
    // 构造器
    constructor(appname:string, name: string) {
        this.appname = appname;
        this.name = name;
    }

    // ========= 5个常见的方法 ========

    // 获取所有！
    public  getAll = (params?: any) => {
        return request({
            method: 'get',
            url: `${this.appname}/${this.name}/`,
            params
        })
    }

    // 获取一个 
    public getOne = (id: any) => {
        return request({
            method: 'get',
            url: `${this.appname}/${this.name}/${id}/`
        })
    }

    // 添加 
    public add = (data: any) => {
        return request({
            method: 'post',
            url: `${this.appname}/${this.name}/`,
            data
        })
    }

    // 修改 
    public edit = (id: any, data: any) => {
        return request({
            method: 'put',
            url: `${this.appname}/${this.name}/${id}/`,
            data
        })
    }

    // 删除
    public del = (id: any) => {
        return request({
            method: 'delete',
            url: `${this.appname}/${this.name}/${id}`
        })
    }
}

export default BaseAPI